package programmercarl.贪心.C14;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

class Solution {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0] == o2[0]) {return o1[1] - o2[1];}
                return  o2[0]-o1[0];
            }
        });
        List<int[]> list = new ArrayList<>();
        for (int[] person : people) {
            list.add(person[1], person);
        }
//        for (int i = 0; i < people.length; i++) {
//            list.add(people[i][1],people[i]);
//        }
        return list.toArray(new int[people.length][]);
    }
}